package com.focus.xyz.mobile.pages;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.core.pages.BasePage;
import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.core.utils.prop.ConfigPropInfo;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chenmeng on 2016/7/22.
 */
public class MHomePage extends BasePage{

    private static final String url = "http://www.xyz.cn/";
//    private static final String url = "http://m.xyz.cn/";
    private Action action;
    private WebDriver driver;
    @FindBy(xpath = "//div[@class='smart-nav-logo']")
    private WebElement mainLogo;
    @FindBy(className = "bg-orange")
    private WebElement prodKind;

    @FindBy(xpath = "//ul[@class='smart-nav-items']")
    private WebElement logo;

    @FindBy(xpath = "//ul[@class='smart-nav-items']/li")
    private List<WebElement> menuList;

    public MHomePage(WebDriver driver,Action action){
        super(driver,action);
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    public void openMainPage() throws Exception{
        action.open(url,new Dimension(375,667),false);
    }

    public void clickProdKind() throws Exception{
        action.click(prodKind);
    }

    public void clickMemMenu(String menuName) throws Exception{
        action.click(mainLogo);
        if(menuList != null && menuList.size()>0){
            for(WebElement e : menuList){
                if(menuName.equals(e.getText().trim())){
                    action.click(e);
                    break;
                }
            }
        }
    }
}
